package com.hadoop.mapreduce;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
/**
 * 内容去重
 * @date 2015年5月7日 下午5:02:16
 * @author zhouxiao
 */
public class WordUniq {
	//map
	public static class TokenizerMapper extends Mapper<Object, Text, Text, Text> {
		public void map(Object key, Text value,Context context)throws IOException, InterruptedException {
			context.write(value, new Text(""));
		}
	}
	//reduce
	public static class IntSumReducer extends Reducer<Text, Text, Text,Text>{
		public void reduce(Text text, Iterable<Text> values,Context context)throws IOException, InterruptedException {
				context.write(text, new Text(""));
		}
		
	}
	 public static void main(String[] args) throws Exception {
		 	String paths="hdfs://master:9000//usr//local//tmp/test//in1.txt,hdfs://master:9000//usr//local//tmp/test//in2.txt";
		    Configuration conf = new Configuration();
		    Job job = new Job(conf, "word uniq");
		    job.setJarByClass(WordUniq.class);
		    job.setMapperClass(TokenizerMapper.class);
		    job.setCombinerClass(IntSumReducer.class);
		    job.setReducerClass(IntSumReducer.class);
		    job.setOutputKeyClass(Text.class);
		    job.setOutputValueClass(Text.class);
		    FileInputFormat.addInputPaths(job,paths);
		    FileOutputFormat.setOutputPath(job, new Path("hdfs://master:9000//usr//local//tmp/test//out"));
		    System.exit(job.waitForCompletion(true) ? 0 : 1);
	}
}
